<?php

namespace Common\Model;

/**
 * Description of HotelPayModel
 * 
 * @author songanwei
 * @date 2015-12-31 
 * @index hotelpay(`hotelentity_id`, `status`)
 */
class HotelPayModel extends BaseModel {

    protected $trueTableName = 'tb_hotel_pay';

    /**
     * 添加客栈支付类型数据
     * @modify songanwei 2015-12-31
     * @modify trainyao 2016-01-09  修改为增加多条
     * @param array $data 封装好的信息
     * @return boolean          执行结果
     */
    public function addInfo($data) {
        $result = $this->addAll($data);

        return empty($result) ? false : true;
    }

    /**
     * 修改客栈支付类型数据
     * @modify songanwei 2015-12-31
     * @param inetegr $hotelTypeId  主键编号
     * @param string $name 客栈支付名称
     * @param integer $type 0=用户自建1=系统自建不可删除
     * @param integer $status 状态
     */
    public function saveInfo($hotelTypeId, $name, $type = 0, $status = 0) {
        $options = array(
            'name' => $name,
            'type' => $type,
            'status' => $status
        );
        $result = $this->where(array('id' => $hotelTypeId))->save($options);
        return $result === false ? false : true;
    }

    /**
     * 根据id获取支付方式数据
     * @modify trainyao 2016-01-14  创建
     * @param   mixin   $payIds 条目id(s)
     * @return array                信息数组
     */
    public function getInfo($payIds) {
        $option = array();
        if(is_array($payIds)) {
            $payIds = implode(',', $payIds);
        }

        $fields = 'id,name,type,status';
        $data = array();
        if(strpos($payIds, ',') !== false) {
            $option['id'] = array('in', $payIds);
            $data = $this->where($option)->field($field)->select();
        } else {
            $option['id'] = $payIds;
            $data = $this->where($option)->field($field)->find();
        }

        return empty($data) ? array() : $data;
    }

    /**
     * 获取客栈所有分销渠道
     * @modify trainyao 2016-01-08 创建
     * @param  integer   $hotelId   客栈ID
     * @return array        信息数组
     */
    public function getInfoByHotel($hotelId) {
        if (is_array($hotelId)) {
            $option['hotelentity_id'] = array('in', $hotelId);
        } else {
            $option['hotelentity_id'] = $hotelId;
        }

        $data = $this->where($option)->select();
        return empty($data) ? array() : $data;
    }

    /**
     * 删除条目
     * @modify trainyao 2016-01-08      创建
     * @param  integer   $hotelId        客栈id
     * @param  integer   $hotelPayId 条目id
     * @return mixin                   删除结果
     */
    public function deleteInfo($hotelId, $hotelPayId) {
        $option = array(
            'hotelentity_id' => $hotelId,
            'status' => NOT_DELETE,
            'id' => $hotelPayId,
        );
        $data = array(
            'status' => IS_DELETE,
        );
        return $this->where($option)->save($data);
    }
}
